/*********************************
 * Themes, rules, and i18n support
 * Locale: Chinese; 涓枃
 *********************************/
(function(factory) {
    typeof module === "object" && module.exports ? module.exports = factory( require( "jquery" ) ) :
    typeof define === 'function' && define.amd ? define(['jquery'], factory) :
    factory(jQuery);
}(function($) {

    /* Global configuration
     */
    $.validator.config({
        //stopOnError: true,
        //focusCleanup: true,
        //theme: 'yellow_right',
        //timely: 2,

        // Custom rules
        rules: {
            digits: [/^\d+$/, "璇峰～鍐欐暟瀛�"]
            ,letters: [/^[a-z]+$/i, "璇峰～鍐欏瓧姣�"]
            ,date: [/^\d{4}-\d{2}-\d{2}$/, "璇峰～鍐欐湁鏁堢殑鏃ユ湡锛屾牸寮�:yyyy-mm-dd"]
            ,time: [/^([01]\d|2[0-3])(:[0-5]\d){1,2}$/, "璇峰～鍐欐湁鏁堢殑鏃堕棿锛�00:00鍒�23:59涔嬮棿"]
            ,email: [/^[\w\+\-]+(\.[\w\+\-]+)*@[a-z\d\-]+(\.[a-z\d\-]+)*\.([a-z]{2,4})$/i, "璇峰～鍐欐湁鏁堢殑閭"]
            ,url: [/^(https?|s?ftp):\/\/\S+$/i, "璇峰～鍐欐湁鏁堢殑缃戝潃"]
            ,qq: [/^[1-9]\d{4,}$/, "璇峰～鍐欐湁鏁堢殑QQ鍙�"]
            ,IDcard: [/^\d{6}(19|2\d)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)?$/, "璇峰～鍐欐纭殑韬唤璇佸彿鐮�"]
            ,tel: [/^(?:(?:0\d{2,3}[\- ]?[1-9]\d{6,7})|(?:[48]00[\- ]?[1-9]\d{6}))$/, "璇峰～鍐欐湁鏁堢殑鐢佃瘽鍙风爜"]
            ,mobile: [/^1[3-9]\d{9}$/, "璇峰～鍐欐湁鏁堢殑鎵嬫満鍙�"]
            ,zipcode: [/^\d{6}$/, "璇锋鏌ラ偖鏀跨紪鐮佹牸寮�"]
            ,chinese: [/^[\u0391-\uFFE5]+$/, "璇峰～鍐欎腑鏂囧瓧绗�"]
            ,username: [/^\w{3,12}$/, "璇峰～鍐�3-12浣嶆暟瀛椼€佸瓧姣嶃€佷笅鍒掔嚎"]
            ,password: [/^[\S]{6,16}$/, "璇峰～鍐�6-16浣嶅瓧绗︼紝涓嶈兘鍖呭惈绌烘牸"]
            ,accept: function (element, params){
                if (!params) return true;
                var ext = params[0],
                    value = $(element).val();
                return (ext === '*') ||
                       (new RegExp(".(?:" + ext + ")$", "i")).test(value) ||
                       this.renderMsg("鍙帴鍙梴1}鍚庣紑鐨勬枃浠�", ext.replace(/\|/g, ','));
            }
            
        },

        // Default error messages
        messages: {
            0: "姝ゅ",
            fallback: "{0}鏍煎紡涓嶆纭�",
            loading: "姝ｅ湪楠岃瘉...",
            error: "缃戠粶寮傚父",
            timeout: "璇锋眰瓒呮椂",
            required: "{0}涓嶈兘涓虹┖",
            remote: "{0}宸茶浣跨敤",
            integer: {
                '*': "璇峰～鍐欐暣鏁�",
                '+': "璇峰～鍐欐鏁存暟",
                '+0': "璇峰～鍐欐鏁存暟鎴�0",
                '-': "璇峰～鍐欒礋鏁存暟",
                '-0': "璇峰～鍐欒礋鏁存暟鎴�0"
            },
            match: {
                eq: "{0}涓巤1}涓嶄竴鑷�",
                neq: "{0}涓巤1}涓嶈兘鐩稿悓",
                lt: "{0}蹇呴』灏忎簬{1}",
                gt: "{0}蹇呴』澶т簬{1}",
                lte: "{0}涓嶈兘澶т簬{1}",
                gte: "{0}涓嶈兘灏忎簬{1}"
            },
            range: {
                rg: "璇峰～鍐檣1}鍒皗2}鐨勬暟",
                gte: "璇峰～鍐欎笉灏忎簬{1}鐨勬暟",
                lte: "璇峰～鍐欐渶澶1}鐨勬暟",
                gtlt: "璇峰～鍐檣1}鍒皗2}涔嬮棿鐨勬暟",
                gt: "璇峰～鍐欏ぇ浜巤1}鐨勬暟",
                lt: "璇峰～鍐欏皬浜巤1}鐨勬暟"
            },
            checked: {
                eq: "璇烽€夋嫨{1}椤�",
                rg: "璇烽€夋嫨{1}鍒皗2}椤�",
                gte: "璇疯嚦灏戦€夋嫨{1}椤�",
                lte: "璇锋渶澶氶€夋嫨{1}椤�"
            },
            length: {
                eq: "璇峰～鍐檣1}涓瓧绗�",
                rg: "璇峰～鍐檣1}鍒皗2}涓瓧绗�",
                gte: "璇疯嚦灏戝～鍐檣1}涓瓧绗�",
                lte: "璇锋渶澶氬～鍐檣1}涓瓧绗�",
                eq_2: "",
                rg_2: "",
                gte_2: "",
                lte_2: ""
            }
        }
    });

    /* Themes
     */
    var TPL_ARROW = '<span class="n-arrow"><b>鈼�</b><i>鈼�</i></span>';
    $.validator.setTheme({
        'simple_right': {
            formClass: 'n-simple',
            msgClass: 'n-right'
        },
        'simple_bottom': {
            formClass: 'n-simple',
            msgClass: 'n-bottom'
        },
        'yellow_top': {
            formClass: 'n-yellow',
            msgClass: 'n-top',
            msgArrow: TPL_ARROW
        },
        'yellow_right': {
            formClass: 'n-yellow',
            msgClass: 'n-right',
            msgArrow: TPL_ARROW
        },
        'yellow_right_effect': {
            formClass: 'n-yellow',
            msgClass: 'n-right',
            msgArrow: TPL_ARROW,
            msgShow: function($msgbox, type){
                var $el = $msgbox.children();
                if ($el.is(':animated')) return;
                if (type === 'error') {
                    $el.css({left: '20px', opacity: 0})
                        .delay(100).show().stop()
                        .animate({left: '-4px', opacity: 1}, 150)
                        .animate({left: '3px'}, 80)
                        .animate({left: 0}, 80);
                } else {
                    $el.css({left: 0, opacity: 1}).fadeIn(200);
                }
            },
            msgHide: function($msgbox, type){
                var $el = $msgbox.children();
                $el.stop().delay(100).show()
                    .animate({left: '20px', opacity: 0}, 300, function(){
                        $msgbox.hide();
                    });
            }
        }
    });
}));